home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / util4 / cdrun.lha / CDRun / CDRun.c < prev    next >
C/C++ Source or Header  |  1995-08-04  |  2KB  |  77 lines

  1. /*************************************************************************
  2. ** $VER: CDRun.c 1.1 (4.8.95)
  3. ** Copyright © 1995 Oliver Roberts
  4. **
  5. ** Compiled with Dice 3.01
  6. **
  7. ** Description: Simple CLI command which takes a path to a command as a
  8. **              parameter, CDs to the location of that command and
  9. **              attempts to execute it.
  10. **
  11. ** Example: "CDRun SYS:Utilities/Format" does the same as this:
  12. **
  13. **          "CD SYS:Utilities"
  14. **          "Format"
  15. */
  16.  
  17. #include <exec/types.h>
  18. #include <exec/execbase.h>
  19. #include <dos/dos.h>
  20.  
  21. #include <proto/dos.h>
  22. #include <proto/exec.h>
  23.  
  24. #include <stdlib.h>
  25.  
  26. const char verstag[] = "\0$VER: CDRun 1.1 (" __COMMODORE_DATE__ ")";
  27. const char copyright[] = "Copyright © 1995 Oliver Roberts";
  28.  
  29. LONG Args[1];
  30.  
  31. void PrintError(void)
  32. {
  33.    UBYTE buffer[80];
  34.    if (Fault(IoErr(),NULL,buffer,80)) {
  35.       PutStr(buffer);
  36.       PutStr("\n");
  37.    }
  38. }
  39.  
  40. void _main(void)
  41. {
  42.    struct RDArgs *rdargs;
  43.    char *path;
  44.    char *ptr;
  45.    char store;
  46.    int ret = RETURN_OK;
  47.    BPTR olddir = -1;
  48.    BPTR dirlock;
  49.  
  50.    if (SysBase->LibNode.lib_Version < 36) _exit(RETURN_FAIL);
  51.  
  52.    rdargs = ReadArgs("COMMAND/F",Args,NULL);
  53.  
  54.    if (Args[0]) {
  55.       path = (char *)Args[0];
  56.       ptr = PathPart(path);
  57.       store = *ptr;
  58.       *ptr = '\0';
  59.       if (dirlock = Lock(path,ACCESS_READ)) {
  60.          olddir = CurrentDir(dirlock);
  61.       }
  62.       else {
  63.          PrintError();
  64.       }
  65.       *ptr = store;
  66.  
  67.       ret = SystemTagList(FilePart(path),NULL);
  68.  
  69.       if (olddir != -1) CurrentDir(olddir);
  70.       UnLock(dirlock);
  71.    }
  72.  
  73.    FreeArgs(rdargs);
  74.  
  75.    _exit(ret);
  76. }
  77.